<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
include_once('../config/field.php');
$ColumnType = 0; //栏目类型:0栏目内容分类,1新闻分类,2产品分类
if (!is_numeric($_GET['ID'])) {MsgBox (1,'ID参数出现非数字错误！','-1');}
$page_field = $customize_field['page']; //自定义字段
if(!is_array($page_field)) $page_field = array();
$pa = $db->SelectSQL("SELECT * FROM `{$dbprefix}article` WHERE `ID` = '{$_GET['ID']}'",1);
if(count($pa)==0){MsgBox (1,'不存在的文章内容！','-1');}
$pa = array_shift($pa);

if($_POST['Action']=='UpDate'){
	$ArticleClick = $ConfigArticleClick == 1 ? $_POST['ArticleClick'] : 0;
	$ArticleSort = $ConfigArticleSort == 1 ? $_POST['ArticleSort'] : 0;
	
	if(!empty($_FILES['ArticleImg']['tmp_name'])){
		$npics = picstreatment(0,'ArticleImg');
		$nURL = $upURL1;
	} else {
		$nURL = $pa['ArticleImg'];
		$npics = true;
	}
	
	$sql_add = $upURL1 = NULL; //自定义字段
	foreach($page_field as $i => $n){
		if($n[2] != 'IMGVARCHAR'){
			$sql_add .= "`{$n[0]}` = '" . trim($_POST[$n[0]]) . "',";
		} else {
			//上传类
			$oeURL = $upURL1 = NULL;
			if(!empty($_FILES[$n[0]]['tmp_name'])){
				picstreatment(0,$n[0]);
				$oeURL = $upURL1;
			} else {
				$oeURL = $pa[$n[0]];
			}
			$sql_add .= "`{$n[0]}` = '" . $oeURL . "',";
		}		
	}	
	
	$SQL = "UPDATE `" . $dbprefix . "article` SET 
	`ArticleRela` = '" . $_POST['ColumnRela'] . "',
	`ArticleTitle` = '" . $_POST['ArticleTitle'] . "',
	`ArticleImg` = '" . $nURL . "',
	`ArticleKeyWord` = '" . $_POST['ArticleKeyWord'] . "',
	`ArticleContent` = '" . $_POST['ArticleContent'] . "',
	`ArticleSource` = '" . $_POST['ArticleSource'] . "',
	`ArticlePublished` = '" . $_POST['ArticlePublished'] . "',  
	`ArticleAudit` = '" . $_POST['ArticleAudit'] . "', 
	`ArticleRecommended` = '" . $_POST['ArticleRecommended'] . "', 
	`ArticleClick` = '" . $ArticleClick . "',{$sql_add}
	`ArticleSort` = '" . $ArticleSort . "' WHERE `ID` = '" . $_GET['ID'] . "';";
	
	unset($ConfigArticleClick,$ConfigArticleSort);
	if($db->ExecuteSQL($SQL)){
		AdminLog(1,$Lang,'修改文章内容(ID:' . $_GET['ID'] . ')，结果：操作成功！'); 
		if($npics !== true){
			MsgBox (1,"内容修改成功，图片上传失败，返回信息：{$npics}","PageUpDate.php?Lang={$Lang}&ID={$_GET['ID']}");
		}		
		if($_POST['isHTML'] == 'yes'){
			$ID = $_GET['ID'];
			MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=ComplexPage&StartID={$ID}&EndID={$ID}");
		}			
		MsgBox (1,'栏目内容修改成功！','PageManage.php?Lang=' . $Lang);
	} else {
		AdminLog(1,$Lang,'修改文章内容(ID:' . $_GET['ID'] . ')，结果：操作失败！'); 
		MsgBox (1,'修改失败，请检查您提交的数据是否正确！','-1');
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link href="../tools/highslide/highslide.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script src="../tools/highslide/highslide.js" type="text/javascript"></script>
<script src="../tools/ckeditor/ckeditor.js" type="text/javascript"></script>
<script src="../js/jquery.js" type="text/javascript"></script>
<script language="javascript">
function trim(str) {
	return str.replace(/(^[\s\u3000]*)|([\s\u3000]*$)/g,"");
}
function FormCheck(){
	if(trim(document.form1.ColumnRela.value)==""){
		alert('请选择所属栏目！');
		document.form1.ColumnRela.focus();
		return false;
	}
	if(trim(document.form1.ArticleTitle.value)==""){
		alert('请填写内容标题！');
		document.form1.ArticleTitle.focus();
		return false;
	}
//	if(document.form1.ArticleContent.value==""){
//		alert('请填写详细内容！');
//		return false;
//	}	
	<?php if($ConfigArticleClick==1){?>
	if(document.form1.ArticleClick.value.match(/^[0-9]\d*$/)==null){ 
		alert("点击数必须为数字！"); 
		document.form1.ArticleClick.focus(); 
		return false; 
	}
	<?php } if($ConfigArticleSort==1){?>
	if(document.form1.ArticleSort.value.match(/^[0-9]\d*$/)==null){ 
		alert("排序字段必须为数字！"); 
		document.form1.ArticleSort.focus(); 
		return false; 
	}	
	<?php }?>
}
hs.graphicsDir = '../tools/highslide/graphics/';
hs.showCredits = false;
hs.outlineType = 'rounded-white';
hs.restoreTitle = '关闭';
$(document).ready(function(){CKEDITOR.replace('ArticleContent');});
</script>
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd">
	<td>&nbsp;</td>
	<td align="right">
		<input type="button" value="发布内容" onClick="javascript:location.href='PageAdd.php?Lang=<?php echo $Lang?>'">
		<input type="button" value="内容管理" onClick="javascript:location.href='PageManage.php?Lang=<?php echo $Lang?>'">		
		<input type="button" value="栏目管理" onClick="javascript:location.href='PageColumnManage.php?Lang=<?php echo $Lang?>'">
	</td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form action="PageUpDate.php?Lang=<?php echo $Lang?>&ID=<?php echo $_GET['ID']?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return FormCheck()">
  <tr>
    <td colspan="3" align="center" class="Main_Title">修改栏目内容<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td align="right">选择栏目：</td>
<td>
<select name="ColumnRela" id="ColumnRela">
<option value="">==请选择栏目==</option>
<?php
$Rs = $db->SelectSQL("SELECT `ID`,`ColumnRela`,`ColumnName`,`ColumnLevel`,`ColumnTime`,`ColumnSort` FROM `" . $dbprefix . "column` WHERE ColumnType = $ColumnType && ColumnLang = $Lang;",2);
@$Rs = sdb::column_sort($Rs);
for ($i=0;$i<count($Rs);$i++ ) {
	Html($Rs[$i]);
	for ($x=1;$x<$Rs[$i][3];$x++){$Spaces .= '├┈┈';} //加与栏目级数相同的空格
	$Rs[$i][3] > 1 ? $Spaces = $Spaces . $Rs[$i][2] : $Spaces = $Rs[$i][2]; //一级栏目前不加空格符
	if($pa['ArticleRela'] != $Rs[$i][1]){
		echo '<option value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	} else {
		echo '<option selected="selected" value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	}
	unset($Spaces);
}
unset($Rs,$i,$x);
?>  		
</select>
<span class="red">*</span></td>
    <td><a href="PageColumnManage.php"><font color="#0000FF">点击添加栏目</font></a></td>
  </tr>
  <tr class="odd">
    <td align="right">内容标题：</td>
    <td><input name="ArticleTitle" type="text" class="input2" id="ArticleTitle" value="<?php echo $pa['ArticleTitle'];?>" maxlength="100" />
    <span class="red">*</span></td>
    <td>&nbsp;</td>
  </tr>
<?php if($ConfigArticleImg==1){?>
  <tr class="odd">
    <td align="right">相关图片：</td>
    <td><input name="ArticleImg" type="file" id="ArticleImg" size="35" /></td>
    <td><?php if(!empty($pa['ArticleImg'])) echo '<a  href="../' .  $pa['ArticleImg'] . '" onclick="return hs.expand(this);">图片已存在(查看)</a>,不更换图片时不用上传,上传将会替换当前图片；';?>
	</td>
  </tr>
<?php } ?>
  <tr class="odd">
  	<td align="right">内容来源：</td>
  	<td><input name="ArticleSource" type="text" class="input2" id="ArticleSource" value="<?php echo $pa['ArticleSource'];?>" maxlength="30" /></td>
  	<td>&nbsp;</td>
  	</tr>
<?php
//自定义字段
foreach ($page_field as $i => &$n){
	$fType = "自定义字段（类型：{$n[2]}）";
	if($n[2] == 'IMGVARCHAR'){
		$input = "<input name=\"{$n[0]}\" type=\"file\" size=\"35\" />";
		$n[2] = 'VARCHAR';
		if(!empty($pa[$n[0]])) $fType = '<a  href="../' .  $pa[$n[0]] . '" onclick="return hs.expand(this);">图片已存在(查看)</a>,不更换图片时不用上传,上传将会替换当前图片；';
	} elseif($n[2] == 'TEXT' || $n[2] == 'MEDIUMTEXT' || $n[2] == 'LONGTEXT'){
		$input = "<textarea name=\"{$n[0]}\" style=\"width:300px; height:120px;\">{$pa[$n[0]]}</textarea>";	
	} else {
		$input = "<input name=\"{$n[0]}\" type=\"text\" class=\"input2\" value=\"{$pa[$n[0]]}\" maxlength=\"50\" />";
	}
	echo "<tr class=\"odd\">
    <td align=\"right\">{$n[1]}：</td>
    <td>{$input}</td>
    <td>{$fType}</td>
	</tr>";
}
//End
?>  
  <tr class="odd">
  	<td align="right">关 键 词：</td>
  	<td><input type="text" name="ArticleKeyWord" id="ArticleKeyWord" value="<?php echo $pa['ArticleKeyWord'];?>" class="input2" /></td>
  	<td>用英文逗号隔开,将被用来作为SEO优化关键词及Tag关键词<br />留空时将采用"网站基本设置"中的搜索关键字作为SEO关键词</td>
  	</tr>
  <tr class="odd">
    <td align="right">详细内容：</td>
    <td colspan="2"><textarea id="ArticleContent" name="ArticleContent" rows="10" cols="80"><?php echo htmlspecialchars($pa['ArticleContent']);?></textarea></td>
</tr>
  <tr class="odd">
  	<td align="right">发 布 人：</td>
  	<td><input name="ArticlePublished" type="text" class="input2" value="<?php echo $pa['ArticlePublished'];?>" id="ArticlePublished" maxlength="30" /></td>
  	<td>&nbsp;</td>
  	</tr>
  <tr class="odd">
  	<td align="right">通过审核：</td>
  	<td><input name="ArticleAudit" type="radio" id="radio1" value="1" <?php if($pa['ArticleAudit']==1) echo 'checked="checked"';?> />
  		是
  		<input name="ArticleAudit" type="radio" id="radio2" value="0" <?php if($pa['ArticleAudit']==0) echo 'checked="checked"';?> />
  		否</td>
  	<td>未通过审核的内容将不在任何页面中显示</td>
  	</tr>
  <tr class="odd">
  	<td align="right">是否推荐：</td>
  	<td><input type="radio" name="ArticleRecommended" id="radio3" value="1" <?php if($pa['ArticleRecommended']==1) echo 'checked="checked"';?> />
  		是
  		<input name="ArticleRecommended" type="radio" id="radio4" value="0" <?php if($pa['ArticleRecommended']==0) echo 'checked="checked"';?> />
  		否</td>
  	<td>&nbsp;</td>
  	</tr>
<?php if($ConfigArticleClick==1){?>	
  <tr class="odd">
    <td align="right">点击次数：</td>
    <td><input name="ArticleClick" type="text" id="ArticleClick" value="<?php echo $pa['ArticleClick'];?>" size="6" maxlength="6" />
      <span class="red">*</span></td>
    <td>不建议修改</td>
  </tr>
<?php } if($ConfigArticleSort==1){?>  
  <tr class="odd">
    <td align="right">排&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;序：</td>
    <td><input name="ArticleSort" type="text" id="ArticleSort" value="<?php echo $pa['ArticleSort'];?>" size="6" maxlength="6" />
      <span class="red">*</span></td>
    <td>值越大越靠前</td>
  </tr>
<?php }?>  
  <tr class="odd">
    <td align="right">发布时间：</td>
    <td><input name="ArticleTime" type="text" disabled="disabled" id="ArticleTime" value="<?php echo $pa['ArticleTime'];?>" readonly="true" /></td>
    <td>&nbsp;</td>
  </tr>
<?php if($WebStaticHTML == 1){?>
  <tr class="odd">
  	<td align="right">生成静态：</td>
  	<td><input name="isHTML" type="checkbox" id="isHTML" value="yes" />生成HTML</td>
  	<td>添加后将同时生成与该内容相关的所有静态页面</td>
  	</tr>
<?php }?>  
  <tr class="odd">
    <td align="right"><input name="Action" type="hidden" id="Action" value="UpDate" /></td>
    <td><input type="submit" name="button" id="button" value="提 交" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" name="button2" id="button2" value="重 置" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="button" value="返 回" class="submit" name="xxx0" onclick="history.back(-1)"></td>
    <td>&nbsp;</td>
  </tr>
  </form>
  </table>
</body>
</html>
